//logs.js
const app = getApp()
const Utils = require("../../utils/util.js");

Page({
  data: {
    isLogin: false, //是否登录
    currentData: 0, //选项卡
    page: 1, // 列表页数
    isAll: false, //是否已加载全部
    djdlist:[],
    drzlist:[],
    dldlist:[],
    ruzlist:[],
    alllist:[],
    scanCodeMsg:''
  },
  onLoad: function () {
    let userId = wx.getStorageSync('userId')
    let that = this
    if (userId) {
      this.setData({
        isLogin: true
      })
      that.getdjdList()
      
    }
  },
   //选项卡开始
   bindchange: function(e) {
    const that = this;
    that.setData({
      currentData: e.detail.current
    })
  },
  //点击切换，滑块index赋值
  checkCurrent: function(e) {
    let that = this;
    console.log(e)
    if (that.data.currentData === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentData: e.target.dataset.current,
        p: 1
      })
      if (e.target.dataset.current == '0') {
        that.setData({
          djdlist: []
        })
        that.getdjdList()
      } else if (e.target.dataset.current == '1') {
        that.setData({
          drzlist: []
        })
        that.getdrzList()
      } else if (e.target.dataset.current == '2') {
        that.setData({
          dldlist: []
        })
        this.getdldList()
      } else if (e.target.dataset.current == '3') {
        that.setData({
          ruzlist: []
        })
        this.getruzList()
      }
      else {
        that.setData({
          alllist: []
        })
        this.getallList()
      }
    }
  },
  getdjdList(){
    var that = this
    let userId = wx.getStorageSync('userId')
    let params={
      enterprise_basic_info_id: userId,
      state: 2,
      page:that.data.page
    }
    Utils.getDataRequest('?s=App.Merchant_Order.OrderList', params, function success(res) {
      console.log(res)
      that.setData({
        djdlist:res.data
      })
    }, function fail(res) {
      //失败回调
      
    }, 'hotel')
  },
  getdrzList(){
    var that = this
    let userId = wx.getStorageSync('userId')
    let params={
      enterprise_basic_info_id: userId,
      state: 6,
      page:that.data.page
    }
    Utils.getDataRequest('?s=App.Merchant_Order.OrderList', params, function success(res) {
      console.log(res)
      that.setData({
        drzlist:res.data
      })
    }, function fail(res) {
      //失败回调
      
    }, 'hotel')
  },
  getdldList(){
    var that = this
    let userId = wx.getStorageSync('userId')
    let params={
      enterprise_basic_info_id: userId,
      state: 7,
      page:that.data.page
    }
    Utils.getDataRequest('?s=App.Merchant_Order.OrderList', params, function success(res) {
      console.log(res)
      that.setData({
        dldlist:res.data
      })
    }, function fail(res) {
      //失败回调
      
    }, 'hotel')
  },
  getruzList(){
    var that = this
    let userId = wx.getStorageSync('userId')
    let params={
      enterprise_basic_info_id: userId,
      state: 3,
      page:that.data.page
    }
    Utils.getDataRequest('?s=App.Merchant_Order.OrderList', params, function success(res) {
      console.log(res)
      that.setData({
        ruzlist:res.data
      })
    }, function fail(res) {
      //失败回调
      
    }, 'hotel')
  },
  getallList(){
    var that = this
    let userId = wx.getStorageSync('userId')
    let params={
      enterprise_basic_info_id: userId,
      state: 0,
      page:that.data.page
    }
    Utils.getDataRequest('?s=App.Merchant_Order.OrderList', params, function success(res) {
      console.log(res)
      that.setData({
        alllist:res.data
      })
    }, function fail(res) {
      //失败回调
      
    }, 'hotel')
  },
  getdetail(e){
    console.log(e)
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '../orderDetail/orderDetail?id=' + id,
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    let userId = wx.getStorageSync('userId')
    let that = this
    if (userId) {
      this.setData({
        isLogin: true
      })
      that.getdjdList()
      
    }


  },
  login(){
    wx.navigateTo({
      url: '../login/login',
    })
  },
  scanCode: function() {
    var that = this;
    wx.scanCode({ //扫描API
      success(res) { //扫描成功
        console.log(res) //输出回调信息
        let id = JSON.parse(res.result).orderId
        console.log(id)
        wx.navigateTo({
          url: '../orderDetail/orderDetail?id=' + id,
        })
      }
    })
  },
})
